<template>
  <div class="app-container">
    <div class="filter-container">
      机器人全局配置:
    </div>
    <el-form ref="dataForm" :rules="rules" :model="temp" label-width="120px" style="width: 400px; margin-left:200px;">
      <el-form-item label="线速度" prop="vSpeed">
        <el-input v-model="temp.vSpeed" type="number" />
      </el-form-item>
      <el-form-item label="角速度" prop="hSpeed">
        <el-input v-model="temp.hSpeed" type="number" />
      </el-form-item>
      <el-form-item label="上报频率" prop="updateStateRate">
        <el-input v-model="temp.updateStateRate" type="number" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="updateData">修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getConfig, saveConfig } from '@/api/robot/robot-config'
export default {
  name: 'RobotConfig',
  data() {
    return {
      listLoading: true,
      temp: {
        id: '',
        vSpeed: '',
        hSpeed: '',
        updateStateRate: '',
        url: ''
      },
      rules: {
      }
    }
  },

  created() {
    this.getList()
  },

  methods: {
    getList() {
      this.listLoading = true
      getConfig({}).then(response => {
        const { data } = response
        this.temp = data
        this.listLoading = false
      })
    },

    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.listLoading = true
          saveConfig(this.temp).then(() => {
            this.listLoading = false
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success',
              duration: 2000
            })
          })
        }
      })
    }
  }
}
</script>
